package night_priority_queue;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import util.RabbitMqUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @BelongsProject: RabbitMQ
 * @BelongsPackage: workQueue
 * @Author: HUI
 * @CreateTime: 2022-04-13 10:05
 * @Description:   测试优先级队列，测试时先启动生产者，因为如果先启动消费者，会导致处理速度太快无法看出效果
 */
public class Producer {
    private static final String QUEUE_NAME = "work";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().priority(5).build();
        String message = "";
        for (int i = 1; i < 11; i++) {
            message = i + "-->消息";
            if (i == 5) {
                channel.basicPublish("", QUEUE_NAME, properties, message.getBytes());
            } else {
                channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
            }
        }
        System.err.println("发送消息完成");
    }
}
